﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;


public partial class Controls_Products_ctrCart : System.Web.UI.UserControl
{
    private int nCurentLang = Support.GetCurrentLanguage();
    private int nDefaultLang = Support.GetDefaultLanguage();
    private int nPageCount = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            InitData();
            BindData();
        }
    }

    private void InitData()
    {

        lblCart.Text = MultipleLanguage.CHOSE_PRODUCT[nCurentLang - 1];
        btnMakePrice.Text = MultipleLanguage.QUOTA[nCurentLang - 1];
    }

    private void BindData()
    {
        clsBasket objBasket = clsBasket.getclsBaskets(Context);
        rptCart.DataSource = objBasket.getclsBasketDetail(nDefaultLang, nCurentLang , 1, Config.PAGESIZE, ref nPageCount);
        rptCart.DataBind();
        int intCountItem = objBasket.getCountItem();
        lblAlert.Text = MultipleLanguage.LBL_TOTAL_ITEM[nCurentLang - 1] + " " + intCountItem + " " + MultipleLanguage.LBL_FOUND_BASKET[nCurentLang - 1]; 
    }

    protected void rptCart_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lnkProductName = (Label)e.Item.FindControl("lblProductname");
            ImageButton btnImage = (ImageButton)e.Item.FindControl("btnImage");
            string sProductName = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductName"));
            if (sProductName.Length > 0)
            {
                lnkProductName.Text = sProductName;
            }
            else
            {
                lnkProductName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductName_Default"));
            }

            btnImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductID"));
            btnImage.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.BASKET_DELETE_CONFIRM[0]);
        }
    }
    protected void rptCart_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                clsBasket objBasket = clsBasket.getclsBaskets(Context);
                objBasket.RemoveItem(nID);
                Response.Redirect(Pages.FrontEnds.HOME);
                break;
        }
    }
    protected void btnMakePrice_Click(object sender, EventArgs e)
    {
        string sLink = Config.ROOT + Pages.FrontEnds.BASKET_DETAIL;
        Response.Redirect(sLink);
    }
}
